/*==========================================================================*\
 |  $Id: JavaStatementElement.java 9 2009-11-06 02:47:13Z VTWoods $
 |*-------------------------------------------------------------------------*|
 |  Copyright (C) 2009 Virginia Tech
 |
 |  This file is part of CloudSpace.
 |
 |  CloudSpace is free software; you can redistribute it and/or modify
 |  it under the terms of the GNU General Public License as published
 |  by the Free Software Foundation; either version 3 of the License, or
 |  (at your option) any later version.
 |
 |  CloudSpace is distributed in the hope that it will be useful,
 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 |  GNU General Public License for more details.
 |
 |  You should have received a copy of the GNU General Public License
 |  along with CloudSpace; if not, see <http://www.gnu.org/licenses/>.
\*==========================================================================*/

package student.web.internal;

import java.io.IOException;
import java.io.Writer;

import org.zkoss.zhtml.Text;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.metainfo.LanguageDefinition;

//-------------------------------------------------------------------------
/**
 *  A base class for creating simple ZK components that represent Java-style
 *  statements.
 *
 *  @author Stephen Edwards
 *  @author Last changed by $Author: VTWoods $
 *  @version $Revision: 9 $, $Date: 2009-11-06 02:47:13 +0000 (Fri, 06 Nov 2009) $
 */
public class JavaStatementElement
    extends Text
    // extends AbstractComponent
{
    //~ Constructors ..........................................................

    // ----------------------------------------------------------
    /**
     * Creates a new object.
     */
    public JavaStatementElement()
    {
        super();
        setVisible(false);
    }


    //~ Methods ...............................................................

//    // ----------------------------------------------------------
//    public boolean isChildable()
//    {
//        return false;
//    }
//
//    // ----------------------------------------------------------
//    public void redraw(Writer out)
//        throws IOException
//    {
//        super.redraw(out);
//    }
    public void redraw(Writer out)
        throws IOException
    {
        if (isIdRequired())
            super.redraw(out);
    }

    protected boolean isIdRequired() {
        final Component p = getParent();
        return p == null || !isVisible()
            || !Components.isAutoId(getId())
            || !isRawLabel(p);
    }

    protected static boolean isRawLabel(Component comp) {
		final LanguageDefinition langdef =
			comp.getDefinition().getLanguageDefinition();
		return langdef != null && langdef.isRawLabel();
	}
}
